<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>云钢</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui-flex.css">
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <style>
        .aui-bar-light{ color: black; }
        .aui-bar-nav.aui-bar-light .aui-iconfont{ color: black; }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav aui-bar-light" id="header">
        <a class="aui-pull-left aui-btn" onclick="backpage()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">我要采购</div>
    </header>
    <div id="app" v-cloak>
        <div class="padding-lr-xl">

            <div class="radius margin-top padding-lr padding-tb" style="background: white;">
                <div class="flex-between">
                    <div class="flex-between"><img src="../../image/send/xx03.png" alt="" style="width: 1.5rem;height: 1.5rem;"><span class="margin-left" style="margin-top: 0.2rem;">钢材售卖货品名称</span></div>
                    <div class="">
                        <!-- <i class="aui-iconfont aui-icon-right"></i> -->
                    </div>
                </div>
                <p class="margin-top">货品规格：中型料</p>
                <p class="margin-top">采购数量：100吨</p>
                <p class="margin-top">采购价格：1.20元/吨</p>
                <div class="margin-top flex-between padding-top" style="border-top: 0.05rem solid #ccc;">
                    <div></div>
                    <div>合计：<span class="text-red">120.00元</span></div>
                </div>
            </div>

            <div class="radius margin-top padding-lr padding-tb-xl" style="background: white;">
                <h3>订单备注</h3>
                <textarea name="" id="" cols="30" rows="10" style="background: #f5f5f5;" class="margin-top padding" placeholder="选填，可填写您对订单的要求~"></textarea>
            </div>
            <p class="margin-top-xxl"><div class="aui-btn aui-btn-info aui-btn-block round" onclick="share()">分享</div></p>
            <p class="margin-top-xxl"><div class="aui-btn aui-btn-info aui-btn-block round" onclick="pay()">立即下单</div></p>
            <p class="margin-top-xxl"><div class="aui-btn aui-btn-info aui-btn-block round" onclick="openapp()">openapp</div></p>


        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/aui-actionsheet.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>

<script type="text/javascript">

    var vm = {
        el: '#app',
        data: {
            list: []
        },
        mounted: function(){
            this.getList();
        },
        methods: {
            getList: function(){
                let that = this;
            }
        }
    }
    var aliPayPlus;
    var wxPayPlus;
    var wx;
    apiready = function() {
        $api.fixStatusBar(
            $api.byId("header")
        );

        aliPayPlus = api.require('aliPayPlus');

        wxPayPlus = api.require('wxPayPlus');
        
        
        // window.app = new Vue(vm);
        

    };
    function openapp(){
        var openApp = api.require('openApp');
        var params = {
            package: 'com.t472518328.cmp',
            url: 'http://www.shanxiyungang.com/index/index/market'
        };
        openApp.openAppMarket(params, function(ret, err) {
            console.log(JSON.stringify(ret))
            console.log(JSON.stringify(err))
            if(ret){
            alert($api.jsonToStr(ret));
            }
        });
    }

    var actionsheet = new auiActionsheet();
    function pay(){
        console.log($api.getStorage('token') == '' ? '未登录' : '已登陆')
        console.log($api.getStorage('token'))
        let payType = 1;
        actionsheet.init({
            frameBounces:true,//当前页面是否弹动，（主要针对安卓端）
            title:"支付方式",
            cancelTitle:'取消支付',
            // destructiveTitle:'红色警告按钮',
            buttons:['微信支付','支付宝支付']
        },function(res){
            if(res){
                payType = res.buttonIndex;
                console.log(payType)
                if(payType == 3){
                    return false;
                }
                api.ajax({
                    url: $api.apiUrl+'pay/pay',
                    method: 'post',
                    timeout: 30,
                    dataType: 'json',
                    returnAll: false,
                    headers: {
                        'token': '6348d0583e5a2e9324dceb70256490bf'
                    },
                    data: {
                        values: {
                            pay_method: payType
                        }
                    }
                }, function(ret, err){
                    console.log(JSON.stringify(ret))
                    console.log(JSON.stringify(err))
                    let payData = ret.data;

                    api.hideProgress();
                    api.toast({
                        msg:ret.msg,
                        duration:1000
                    });
                    if (ret.code == 200) {
                        console.log(payType)
                        if(payType == 2){
                            aliPayPlus.payOrder({
                                orderInfo: payData,
                                // sandbox: true
                            }, function(ret, err){
                                // console.log(JSON.stringify(ret))
                                // console.log(JSON.stringify(err))
                                api.alert({
                                    title: '支付结果',
                                    msg: ret.code,
                                    buttons: ['确定']
                                });
                            })
                        }else if(payType == 1){
                                // wxPayPlus.config({
                                //     apiKey: 'wx93e87f6a5fb093fe',
                                //     mchId: '1612213028',
                                //     partnerKey: 'shanxiyungangSX678sxyg1612213028',
                                //     notifyUrl: 'http://www.shanxiyungang.com/api/wxpay/notices'
                                // }, function(ret, err) {
                                //     console.log(JSON.stringify(ret))
                                //     console.log(JSON.stringify(err))
                                //     if (ret.status) {
                                //         alert('配置商户支付参数成功');
                                //     } else {
                                //         alert(err.code);
                                //     }
                                // });

                                // wxPayPlus.pay({
                                //     description: 'iPad mini 16G 白色',
                                //     totalFee: '1',
                                //     tradeNo: 'wx3011005472649643ab8c556cfde',
                                //     spbillCreateIP: '171.117.1.140',
                                //     deviceInfo: '013467007045764',
                                //     detail: 'iPad mini 16G 白色',
                                //     attach: '说明',
                                //     feeType: 'CNY',
                                //     // timeStart: '20091225091010',
                                //     // timeExpire: '20092227091010',
                                //     goodsTag: 'WXG',
                                //     productId: '12235413214070356458058',
                                //     openId: 'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o'
                                // }, function(ret, err) {
                                //     console.log(JSON.stringify(ret))
                                //     console.log(JSON.stringify(err))
                                //     if (ret.status) {
                                //         alert(ret.result);
                                //     } else {
                                //         alert(err.code);
                                //         alert(err.msg);
                                //     }
                                // });
                            //         payData=JSON.parse(payData);
                            // console.log(payData.sign)
                            // wxPayPlus.payOrder({
                            //     apiKey: payData.appId,
                            //     orderId: payData.prepayId,
                            //     mchId: payData.partnerId,
                            //     nonceStr: payData.nonceStr,
                            //     timeStamp: payData.timeStamp,
                            //     package: payData.package,
                            //     sign: payData.sign
                            // }, function(ret,err){
                            //     console.log(JSON.stringify(ret))
                            //     console.log(JSON.stringify(err))
                            //     if (ret.status) {
                            //         //支付成功
                            //         alert(JSON.stringify(ret));
                            //     } else {
                            //     console.log(JSON.stringify(err))
                            //         // alert(3);
                            //         alert(err.code)

                            //     }
                            // });
                            wxPayPlus.payOrder({
                                apiKey: payData.appid,
                                orderId: payData.prepayid,
                                mchId: payData.partnerid,
                                nonceStr: payData.noncestr,
                                timeStamp: payData.timestamp,
                                package: payData.package,
                                sign: payData.sign
                            }, function(ret,err){
                                console.log(JSON.stringify(ret))
                                console.log(JSON.stringify(err))
                                if (ret.status) {
                                    //支付成功
                                    alert(JSON.stringify(ret));
                                } else {
                                console.log(JSON.stringify(err))
                                    // alert(3);
                                    alert(err.code)

                                }
                            });

                            // wxPayPlus.getOrderId({
                            //     info: payData
                            // }, function(ret,err){
                            //     console.log(1)
                            //     console.log(JSON.stringify(ret.prepay_id))
                            //     console.log(JSON.stringify(err))
                            //     api.ajax({
                            //         url: $api.apiUrl+'pay/second',
                            //         method: 'post',
                            //         timeout: 30,
                            //         dataType: 'json',
                            //         returnAll: false,
                            //         headers: {
                            //             'token': '1c31bf95a7000690c1ac2c16edf331df'
                            //         },
                            //         data: {
                            //             values: {
                            //                 prepay_id: ret.prepay_id
                            //             }
                            //         }
                            //     }, function(ret, err){
                            //         console.log(JSON.stringify(ret))
                            //         console.log(JSON.stringify(err))
                            //         let payData = ret.data;
                            //         // console.log(payData.appid)
                            //          wxPayPlus.payOrder({
                            //     apiKey: payData.appid,
                            //     orderId: payData.prepayid,
                            //     mchId: payData.partnerid,
                            //     nonceStr: payData.noncestr,
                            //     timeStamp: payData.timestamp,
                            //     package: payData.package,
                            //     sign: payData.sign
                            // }, function(ret1,err1){
                            //     console.log(JSON.stringify(ret1))
                            //     console.log(JSON.stringify(err1))
                            //     if (ret1.status) {
                            //         //支付成功
                            //         alert(JSON.stringify(ret1));
                            //     } else {
                            //     console.log(JSON.stringify(err1))
                            //         alert(3);
                            //         alert(err1.code)
                            //     console.log(JSON.stringify(err))

                            //     }
                            // });
                            //     })
                            // })
                        }
                    }
                })
    
            }
        })

    }

    function backpage(){
        api.closeWin({
            name: api.winName
        })
        
    }

</script>

</html>
